<?php

namespace App\Http\Validators;

use Illuminate\Contracts\Validation\Validator as ValidatorC;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Symfony\Component\HttpFoundation\Response;

class Validator extends FormRequest
{
    protected function failedValidation(ValidatorC $validator)
    {
        throw (new HttpResponseException(response()->json(['code' => 1, 'message' => current(current($validator->errors()))[0]], Response::HTTP_UNAUTHORIZED)));
    }
}
